// 运行时配置
import { useState } from 'react';

// 全局初始化数据配置，用于 Layout 用户信息和权限初始化
// 更多信息见文档：https://umijs.org/docs/api/runtime-config#getinitialstate
export async function getInitialState(): Promise<{ name: string }> {
  return { name: '@umijs/max' };
}

// export const layout = () => {
//   return {
//     logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
//     menu: {
//       locale: false,
//     },
//   };
// };

export function useQiankunStateForSlave() {
  const [globalState, setGlobalState] = useState<any>({
    slogan: 'Hello MicroFrontend',
  });

  return {
    globalState,
    setGlobalState,
  };
}

export const qiankun = {
  lifeCycles: {
    afterMount(props: any) {
      console.log(
        `%c 主应用 【afterMount】：`,
        'color: #f95; font-size: 18px',
        props,
      );
    },
    beforeLoad(props: any) {
      console.log(
        `%c 主应用 【beforeLoad】：`,
        'color: #03ccdd; font-size: 18px;',
        props,
      );
    },
    beforMount(props: any) {
      console.log(
        `%c 主应用 【beforMount】：`,
        'color: green; font-size: 18px',
        props,
      );
    },
    beforUnMount(props: any) {
      console.log(
        `%c 主应用 【beforUnMount】：`,
        'color: yellow; font-size: 18px',
        props,
      );
    },
  },
};
